package cn.liyunqi.prplug.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Auther: li.yunqi
 * @Date: 2019/8/9 14:16
 * @Description: TODO
 */
public class MD5Util {

    /**
     * 对字符串进行32Bit的MD5加密
     *
     * @param plainText，需要进行加密的字符串
     * @return String 返回经过32位MD5加密后的字符串
     *
     * @author:
     * @CreateTime:2012-8-2
     * @ModifyTime: 2012-8-2
     * */
    public static String get32BitMd5EncString(String plainText)
    {
        String result = null;
        try
        {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++)
            {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            result = buf.toString();
        } catch (NoSuchAlgorithmException e)
        {
            e.printStackTrace();
        }
        return result;
    }
}
